#!/bin/bash

# Usage: ./extract_all_bags_sound_direction.sh

# Warning: this will overwrite all previously generated files with the same name!


input_dir=/media/janko/EmPRISEData/Projects/SocialDining/Data/bag
output_dir=/media/janko/EmPRISEData/Projects/SocialDining/Data/raw/sound-direction
cnt=0

echo "Input path: ${input_dir}"
echo "Output path: ${output_dir}"

for bag_filepath in ${input_dir}/*.bag
do

   cnt=$((cnt+1))
   session_id=$(basename -- $bag_filepath)
   session_id=${session_id:0:-4}
   start_time=$(date +%s)

   rostopic echo -b ${bag_filepath} -p /sound_direction > ${output_dir}/${session_id}.csv & wait $!

   end_time=$(($(date +%s)-start_time))
   echo "Session ID:" $session_id
   echo "Time taken (seconds): "$end_time
   echo ""
done

echo ""
echo "Extracted sound direction from ${cnt} bag files."
